import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.2

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    color: "blue";
    title: "消息对话框";
    id: root;
    menuBar: MenuBar{
        Menu {
            title: "帮助";
            MenuItem{
                text: "关于";
                onTriggered: root.showAbout();
            }
        }
    }

    property MessageDialog aboutDlg: null
    function showAbout(){
        if(aboutDlg == null){
            aboutDlg = Qt.createQmlObject(
                        'import QtQuick 2.2;
                        import QtQuick.Dialogs 1.1;
                        MessageDialog{
                            icon: StandardIcon.Information;
                            title: "关于";\n
                            text: "仅仅是个示例";\n
                            standardButtons:StandardButton.Ok;
                        }',
                        root, "aboutDlg");
            aboutDlg.accepted.connect(onAboutDlgClosed);
            aboutDlg.rejected.connect(onAboutDlgClosed);
            aboutDlg.visible = true;
        }
    }
    function onAboutDlgClosed(){
        aboutDlg.destroy();
        aboutDlg = null;
    }
}
